// g++ x.cpp -std=c++11
#include <iostream>
#include <vector>
#include "Lexer.h"
#include "SQLExprParser.h"

#include "../utils/log.h"

int main()
{

	try
	{

		string_ptr e = make_string_ptr("AGE > 506");
		SQLExprParser *exprParser = new SQLExprParser(e);
		SQLBinaryOpExpr_ptr binaryOpExpr = std::dynamic_pointer_cast<SQLBinaryOpExpr>(exprParser->getExpr());
		LOG_INFO << (binaryOpExpr->getOperator())->getName()->c_str() ;

		// Assert.assertEquals(SQLBinaryOperator.GreaterThan, binaryOpExpr.getOperator());

		SQLIdentifierExpr_ptr left = std::dynamic_pointer_cast<SQLIdentifierExpr>(binaryOpExpr->getLeft());
		LOG_INFO <<  (left->getName()) ;
		SQLIntegerExpr_ptr right = std::dynamic_pointer_cast<SQLIntegerExpr>(binaryOpExpr->getRight());
		// RNumber *n = right->getNumber();
		// int a = boost::rational_cast<int> (n);
		LOG_INFO <<  (right->intValue()) ;

		// Assert.assertEquals("AGE", left.getName());
		// Assert.assertEquals(5, right.getNumber().intValue());
		//
		//

		string_ptr sql = make_string_ptr("a > b");
		string_ptr sql_c = make_string_ptr("a > 2");

		SQLBinaryOpExpr *exprA, *exprB, *exprC;
		{
			SQLExprParser *parser = new SQLExprParser(sql);
			SQLBinaryOpExpr_ptr exprA = std::dynamic_pointer_cast<SQLBinaryOpExpr>(parser->getExpr());
			auto attrs = exprA->getAttributes();
			for (auto attr : *attrs)
			{
				LOG_INFO <<  attr.first;
			}
		}
		{
			SQLExprParser *parser = new SQLExprParser(sql);
			SQLBinaryOpExpr_ptr exprB = std::dynamic_pointer_cast<SQLBinaryOpExpr>(parser->getExpr());
		}
		{
			SQLExprParser *parser = new SQLExprParser(sql);
			SQLBinaryOpExpr_ptr exprC = std::dynamic_pointer_cast<SQLBinaryOpExpr>(parser->getExpr());
		}
	}
	catch (ParserException *e)
	{
		std::cout << e->what() ;
	}

	return 0;
}
